﻿namespace TyporaImgToBase64
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            CreateTimer();
            StartTimer();
        }

        public System.Windows.Forms.Timer timer = new()
        {
            Interval = 1000
        };

        public void TimerTick(object sender, EventArgs e)
        {
            Program.seconds++;
            LBTimeCount.Text = "耗时: " + Program.seconds + " 秒";
        }

        public void CreateTimer()
        {
            timer.Tick += new EventHandler(TimerTick);
        }

        public void StartTimer()
        {
            timer.Start();
        }

        public void StopTimer()
        {
            timer.Stop();
        }

        protected override void OnClosed(EventArgs e)
        {
            // 关闭时停止计时
            StopTimer();
            base.OnClosed(e);
            // 结束线程
            Application.ExitThread();
        }
    }
}
